/** Treatment Record */
package domain.records;


import java.io.Serializable;
import java.util.Date;

import org.json.JSONObject;

import domain.appointment.Appointment;
import domain.doctor.Doctor;
import domain.nurse.Nurse;
import domain.patient.Patient;

/** 
 * 
 * Treatment Record contains information about the appoitnment 
 * @author jessienewman
 * @version 1.0
 * */
public class TreatmentRecord implements Serializable{
	/** Field id. */
	private Integer id;
	
	/** Field nurse. */
	private Nurse nurse;
	
	/** Field symptoms.	 */
	private String symptoms;
	
	/** Field pulse. */
	/** Field bloodpressure. */
	/** Field temperature.	 */
	/** Field weight. */
	/** Field height. */
	private int height, weight, temperature, bloodpressure, pulse;
	
	/** Field diagnosis. */
	private String diagnosis;
	
	/** Field orders. */
	private DoctorsOrders orders;
	
	/** Field appt. */
	private Appointment appt;
	
	/** creates a treatment record with no data * 
	 * @param d Doctor
	 * @param p Patient
	 */
	public TreatmentRecord(Doctor d, Patient p) {
		this(null, "", -1, -1, -1, -1, -1, "", new DoctorsOrders(d, p));
	}
	
	/** 
	 * creates a treatment record
	 * @param nurse attending nurse
	 * @param symptoms symptoms patient complains of
	 * @param height height during visit
	 * @param weight weight during visit
	 * @param temperature temperature during visit
	 * @param bloodpressure blooppressure during visit
	 * @param pulse pulse during visit
	 * @param diagnosis diagnosis
	 * @param orders doctors orders
	 */
	public TreatmentRecord(Nurse nurse,  // $codepro.audit.disable largeNumberOfParameters
			String symptoms, int height, int weight, int temperature, int bloodpressure, 
			int pulse, String diagnosis, DoctorsOrders orders){
		this.nurse=nurse;
		this.symptoms=symptoms;
		this.height=height;
		this.weight=weight;
		this.temperature=temperature;
		this.bloodpressure=bloodpressure;
		this.pulse=pulse;
		this.diagnosis=diagnosis;
		this.orders=orders;
	}
	
	public TreatmentRecord(final JSONObject json) {
		populateFromJSON(json);
	}
	
	/**
	 * Method setAppointment.
	 * @param appt Appointment
	 */
	public void setAppointment(Appointment appt) {
		this.appt = appt;
	}
	
	/**
	 * Method getAppointment.
	
	 * @return Appointment */
	public Appointment getAppointment() {
		return appt;
	}

	/**
	 * Method setId.
	 * @param id Integer
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	
	/**
	 * Method getId.
	
	 * @return Integer */
	public Integer getId() {
		return id;
	}

	/**
	 * Method getDoctor.
	
	 * @return Doctor */
	public Doctor getDoctor() {
		return (appt == null) ? null : appt.getDoctor();
	}

	/**
	 * Method getNurse.
	
	 * @return Nurse */
	public Nurse getNurse() {
		return nurse;
	}

	/**
	 * Method setNurse.
	 * @param nurse Nurse
	 */
	public void setNurse(Nurse nurse) {
		this.nurse = nurse;
	}

	/**
	 * Method getPatient.
	
	 * @return Patient */
	public Patient getPatient() {
		return (appt == null) ? null : appt.getPatient();
	}

	/**
	 * Method getDate.
	
	 * @return Date */
	public Date getDate() {
		return (appt == null) ? null : appt.getDate();
	}

	/**
	 * Method getSymptoms.
	
	 * @return String */
	public String getSymptoms() {
		return symptoms;
	}

	/**
	 * Method setSymptoms.
	 * @param symptoms String
	 */
	public void setSymptoms(String symptoms) {
		this.symptoms = symptoms;
	}

	/**
	 * Method getHeight.
	
	 * @return int */
	public int getHeight() {
		return height;
	}

	/**
	 * Method setHeight.
	 * @param height int
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * Method getWeight.
	
	 * @return int */
	public int getWeight() {
		return weight;
	}

	/**
	 * Method setWeight.
	 * @param weight int
	 */
	public void setWeight(int weight) {
		this.weight = weight;
	}

	/**
	 * Method getTemperature.
	
	 * @return int */
	public int getTemperature() {
		return temperature;
	}

	/**
	 * Method setTemperature.
	 * @param temperature int
	 */
	public void setTemperature(int temperature) {
		this.temperature = temperature;
	}

	/**
	 * Method getBloodpressure.
	
	 * @return int */
	public int getBloodpressure() {
		return bloodpressure;
	}

	/**
	 * Method setBloodpressure.
	 * @param bloodpressure int
	 */
	public void setBloodpressure(int bloodpressure) {
		this.bloodpressure = bloodpressure;
	}

	/**
	 * Method getPulse.
	
	 * @return int */
	public int getPulse() {
		return pulse;
	}

	/**
	 * Method setPulse.
	 * @param pulse int
	 */
	public void setPulse(int pulse) {
		this.pulse = pulse;
	}

	/**
	 * Method getDiagnosis.
	
	 * @return String */
	public String getDiagnosis() {
		return diagnosis;
	}

	/**
	 * Method setDiagnosis.
	 * @param diagnosis String
	 */
	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}

	/**
	 * Method getOrders.
	
	 * @return DoctorsOrders */
	public DoctorsOrders getOrders() {
		return orders;
	}

	/**
	 * Method setOrders.
	 * @param orders DoctorsOrders
	 */
	public void setOrders(DoctorsOrders orders) {
		this.orders = orders;
	}
	
	/**
	 * Method toString.
	
	 * @return String */
	public String toString() {
		return super.toString();
	}
	
	public JSONObject getJSON() {
		final JSONObject json = new JSONObject();
		json.put("appointment", appt.getJSON());
		json.put("bloodPressure", bloodpressure);
		json.put("diagnosis", diagnosis);
		json.put("height", height);
		json.put("treatmentRecordId", id);
		json.put("nurse", nurse.getJSON());
		json.put("doctorsOrders", orders.getJSON());
		json.put("pulse", pulse);
		json.put("symptoms", symptoms);
		json.put("temperature", temperature);
		json.put("weight", weight);
		return json;
	}
	
	public void populateFromJSON(final JSONObject json) {
		setAppointment(new Appointment(json.getJSONObject("appointment")));
		setBloodpressure(json.getInt("bloodPressure"));
		setDiagnosis(json.getString("diagnosis"));
		setHeight(json.getInt("height"));
		setId(json.getInt("treatmentRecordId"));
		setNurse(new Nurse(json.getJSONObject("nurse")));
		setOrders(new DoctorsOrders(json.getJSONObject("doctorsOrders")));
		setPulse(json.getInt("pulse"));
		setSymptoms(json.getString("symptoms"));
		setTemperature(json.getInt("temperature"));
		setWeight(json.getInt("weight"));
	}
}
